// 绝对位置
function getURL() {
	return location.protocol + "//" + location.host + "/";
}

/*
 * 显示对象 name 对象ID或CLASS，类型为字符串，ID用#开头，CLASS用.开头; delay动画效果，类型为数字；
 */
function showObj(name, delay) {
	if (typeof (delay) == 'undefined') {
		$(name).show();
	} else {
		if (typeof (delay) == 'number') {
			$(name).show(delay);
		} else {
			$(name).show();
		}
	}
}

/*
 * 隐藏对象 name 对象ID或CLASS，类型为字符串，ID用#开头，CLASS用.开头; delay动画效果，类型为数字；
 */
function hideObj(name, delay) {
	if (typeof (delay) == 'undefined') {
		$(name).hide();
	} else {
		$(name).hide(delay);
	}
}

/*
 * 格式化日期 formatDate(number) number为数字时反回当前系统日期+number天，如果为负数则减number天，如果为0则返回今天
 * formatDate(string) string格式为2010-2-2或2010-02-05，反回string参数的下一天
 */
function formatDate(n, z) {
	if (typeof (z) == "undefined") {
		z = 1;
	}
	if (typeof (n) == "number") {
		var uom = new Date();
		uom.setDate(uom.getDate() + n);
		var y = uom.getFullYear();
		var m = (uom.getMonth() + 1);
		var d = uom.getDate();
		m = m > 9 ? m : '0' + m;
		d = d > 9 ? d : '0' + d;
		uom = y + "-" + m + "-" + d;
	}
	if (typeof (n) == "string") {
		var chs = new Array();
		chs = n.split("-");
		var years = new Date(chs[0], chs[1] - 1, chs[2]);
		var strTimes = new Date(years - 0 + z * 86400000);
		var y = strTimes.getFullYear();
		var m = (strTimes.getMonth() + 1);
		var d = strTimes.getDate();
		m = m > 9 ? m : '0' + m;
		d = d > 9 ? d : '0' + d;
		uom = y + "-" + m + "-" + d;
	}
	return uom;
}
// 显示白背景LOADING
function whiteBg() {
	var h = $(window).height();
	var w = $(window).width();
	var sl = $(window).scrollLeft();
	var st = $(window).scrollTop();
	var bg = '<div id="whiteBg" style="position:absolute;height:' + h
			+ 'px; width:' + w + 'px;background:#FFF; top:' + st + 'px; left:'
			+ sl + 'px;z-index:100;"></div>';
	var img = '<div id="loadImg" style="position:absolute; z-index:101; left:'
			+ (sl + (w / 2 - 30)) + 'px; top:' + (st + (h / 2 - 30))
			+ 'px;display:none; text-align:center;"><img src="' + getURL()
			+ 'images/loading/25.gif"  /><br /><br /><img id="loadImg" src="'
			+ getURL() + 'images/loading/26.gif"  /></div>';
	$("body").append(bg).append(img);
	if ($.browser.msie) { // IE浏览器
		if ($.browser.version == "6.0") {
			$("#whiteBg").bgIframe();
		}
	}
	$("#whiteBg").fadeTo("100", 0.5);
	$("#loadImg").fadeIn("fast");
	$(window).resize(function() {
		if ($("#whiteBg").length > 0) {
			$("#whiteBg").css({
				left : $(window).scrollLeft(),
				top : $(window).scrollTop(),
				width : $(window).width(),
				height : $(window).height()
			});
			$("#loadImg").css({
				left : ($(window).scrollLeft() + ($(window).width() / 2 - 25)),
				top : ($(window).scrollTop() + ($(window).height() / 2 - 25))
			});
		}
	});
	$(window).scroll(function() {
		if ($("#whiteBg").length > 0) {
			$("#whiteBg").css({
				left : $(window).scrollLeft(),
				top : $(window).scrollTop(),
				width : $(window).width(),
				height : $(window).height()
			});
			$("#loadImg").css({
				left : ($(window).scrollLeft() + ($(window).width() / 2 - 25)),
				top : ($(window).scrollTop() + ($(window).height() / 2 - 25))
			});
		}
	});

}
// 移除白背景
function removeWhiteBg() {
	$("#whiteBg").remove();
	$("#loadImg").remove();
	$("body #whiteBg").remove();
	$("body #loadImg").remove();
}
// ie6input
$(function() {
	if ($(".pageNo").length > 0) {
		$(".pageBut2").hover(function() {
			$(this).addClass("pageBut3");
		}, function() {
			$(this).removeClass("pageBut3");
		});
	}
	;
	if ($(".tablesorter").length > 0) {
		if ($(".tablesorter").outerWidth() < $(window).width()) {
			$(".tablesorter").width("100%");
		}
	}
	if ($.browser.msie) { // IE浏览器
		if ($.browser.version == "6.0") {
			$("input[type='text']").addClass("ie6input");
			$("input[type='radio']").addClass("inputRradio");
			$("input[type='checkbox']").addClass("inputRradio");
			if ($(window).width() < 900) {
				$(".content").width(900);
			}// iE6的内容最小宽度为780px

			$(window).resize(function() {
				if ($(window).width() < 900) {
					$(".content").width(900);

				} else {
					$(".content").width("100%");
				}
			});
		}
	}

});
// 返回时间戳
function timestamp() {
	var timestamp = (new Date()).valueOf();// 时间戳
	var randomnumber = Math.floor(Math.random() * 100000);// 随机数
	return (timestamp + "" + randomnumber);

}

(function($) {
	$.fn.bgIframe = $.fn.bgiframe = function(s) {
		if ($.browser.msie && /6.0/.test(navigator.userAgent)) {
			s = $.extend({
				top : 'auto',
				left : 'auto',
				width : 'auto',
				height : 'auto',
				opacity : true,
				src : 'javascript:false;'
			}, s || {});
			var prop = function(n) {
				return n && n.constructor == Number ? n + 'px' : n;
			}, html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'
					+ s.src
					+ '"'
					+ 'style="display:block;position:absolute;z-index:-1;'
					+ (s.opacity !== false ? 'filter:Alpha(Opacity=\'0\');'
							: '')
					+ 'top:'
					+ (s.top == 'auto' ? 'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')'
							: prop(s.top))
					+ ';'
					+ 'left:'
					+ (s.left == 'auto' ? 'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')'
							: prop(s.left))
					+ ';'
					+ 'width:'
					+ (s.width == 'auto' ? 'expression(this.parentNode.offsetWidth+\'px\')'
							: prop(s.width))
					+ ';'
					+ 'height:'
					+ (s.height == 'auto' ? 'expression(this.parentNode.offsetHeight+\'px\')'
							: prop(s.height)) + ';' + '"/>';
			return this.each(function() {
				if ($('> iframe.bgiframe', this).length == 0)
					this.insertBefore(document.createElement(html),
							this.firstChild);
			});
		}
		return this;
	};
})(jQuery);

/**
 * 删除通用方法
 * 
 * @param url
 * @return
 */
function del(formId, url) {
	if (confirm('确认删除?')) {
		$("#" + formId).attr("action", url);
		$("#" + formId).submit();
	}
}

function clearForm(formName) {
	var formObj = document.forms[formName];
	var formEl = formObj.elements;
	for ( var i = 0; i < formEl.length; i++) {
		var element = formEl[i];
		if (element.type == 'submit') {
			continue;
		}
		if (element.type == 'reset') {
			continue;
		}
		if (element.type == 'button') {
			continue;
		}
		if (element.type == 'hidden') {
			continue;
		}

		if (element.type == 'text') {
			element.value = '';
		}
		if (element.type == 'textarea') {
			element.value = '';
		}
		if (element.type == 'checkbox') {
			element.checked = false;
		}
		if (element.type == 'radio') {
			element.checked = false;
		}
		if (element.type == 'select-multiple') {
			element.selectedIndex = -1;
		}
		if (element.type == 'select-one') {
			element.selectedIndex = -1;
		}
	}
}

// 将毫秒换算成时分秒
function MillisecondToDate(msd) {
	var time = parseFloat(msd) / 1000;
	if (null != time && "" != time) {
		if (time > 60 && time < 60 * 60) {
			time = parseInt(time / 60.0)
					+ "分钟"
					+ parseInt((parseFloat(time / 60.0) - parseInt(time / 60.0)) * 60)
					+ "秒";
		} else if (time >= 60 * 60 && time < 60 * 60 * 24) {
			time = parseInt(time / 3600.0)
					+ "小时"
					+ parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)
					+ "分钟"
					+ parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) - parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60)
					+ "秒";
		} else {
			time = parseInt(time) + "秒";
		}
	}
	return time;
}

function getWeek(date) {
	var now = new Date();
	date = new Date(date);
	date.setHours(now.getHours(), now.getMinutes(), now.getSeconds(), now
			.getMilliseconds());
	var day = (date - now) / 24 / 1000 / 60 / 60;
	var result = '';
	if (day < 1) {
		result = "今天";
	} else if (day >= 1 & Math.ceil(day) < 2) {
		result = "明天";
	} else if (day >= 2 & day < 3) {
		result = "后天";
	} else {
		date = new Date(date);
		switch (date.getDay()) {
		case 0:
			result = "星期天";
			break;
		case 1:
			result = "星期一";
			break;
		case 2:
			result = "星期二";
			break;
		case 3:
			result = "星期三";
			break;
		case 4:
			result = "星期四";
			break;
		case 5:
			result = "星期五";
			break;
		case 6:
			result = "星期六";
			break;
		}
	}
	return result;
}

function strToDate(string) {
	var f = string.split(' ', 2);
	var d = (f[0] ? f[0] : '').split('-', 3);
	var t = (f[1] ? f[1] : '').split(':', 3);
	return new Date(parseInt(d[0], 10) || null, (parseInt(d[1], 10) || 1) - 1,
			parseInt(d[2], 10) || null, parseInt(t[0], 10) || null, parseInt(
					t[1], 10)
					|| null, parseInt(t[2], 10) || null);
}
